const douban=require("../../libraries/douban.js");
Page({
  data:{
    subtitle:"请在此输入搜索内容",
    movies:[],    
    search: '',
    loading: false,
    hasMore: false
  },
  doLoad(appand){
      douban.find("search",this.data.page++,this.data.size,this.data.search)
          .then(d=>{
                if (d.subjects&&d.subjects.length) {
                    
                    this.setData({subtitle:d.title,movies:this.data.movies.concat(d.subjects),loading:false});
                }else{
                    this.setData({ hasMore: false, loading: false })
                }
            }
          )
          .catch(e=>{
            this.setData({ subtitle: '获取数据异常', movies: [], loading: false })
            console.error(e)
          });
  },
loadMore () {
    if (!this.data.hasMore) return
    this.setData({ subtitle: '加载中...', loading: true });
    this.doLoad(true);  
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  search:function(e){
    if (!e.detail.value) return
    this.setData({ subtitle: '加载中...', hasMore: true, loading: true, search: e.detail.value });
    this.doLoad();
  }
})